
// 声明：

//   ##   ： 拼接前后两个字符串
#define SingletonCreate_h(name) +(instancetype)shared##name;


// 实现：
// 在ARC环境下
#if __has_feature(objc_arc)
#define SingletonCreate_m(name) \
+(instancetype)shared##name{ \
return [[self alloc] init]; \
}\
\
- (id)copyWithZone:(NSZone *)zone{\
return self;\
}\
\
+ (instancetype)allocWithZone:(struct _NSZone *)zone {\
static id instance;\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{\
instance = [super allocWithZone:zone];\
});\
return instance;\
}


// 在MRC环境下
#else
#define SingletonCreate_m(name) \
+(instancetype)shared##name{ \
return [[self alloc] init]; \
}\
\
- (id)copyWithZone:(NSZone *)zone{\
return self;\
}\
\
+ (instancetype)allocWithZone:(struct _NSZone *)zone {\
static id instance;\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{\
instance = [super allocWithZone:zone];\
});\
return instance;\
}\
- (oneway void)release {\
\
}\
\
- (instancetype)autorelease {\
return self;\
}\
\
- (instancetype)retain {\
return self;\
}

#endif

